package com.jiazhong.servlets;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
/*展示无需局部配置的 Servlet 如何使用全局共享参数*/
public class ServletTest07 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //调用config对象
        ServletContext servletContext = this.getServletContext();
        //根据参数的名称获取参数值
        String param1 = servletContext.getInitParameter("param1");
        System.out.println(param1);
        //获取所有的参数的名称
        Enumeration<String> initParameterNames = servletContext.getInitParameterNames();
        //遍历得到的参数的名称
        while (initParameterNames.hasMoreElements()) {
            String string = initParameterNames.nextElement();
            System.out.println(string);
        }
    }
}
